package linwen.wang.service;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author wlw
 * @date 2023/3/9 10:41 PM
 */
@Service
@Slf4j
public class RabbitMqListener {

    @RabbitListener(queues = "directQueue")
    public void listener(String msg,Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        log.info("success lstener  tag {} message: {}",deliveryTag,msg);


        // ack返回false，requeue-true并重新回到队列
        //channel.basicNack(deliveryTag, false, true);
        //basic.reject方法拒绝deliveryTag对应的消息，第二个参数是否requeue，true则重新入队列，否则丢弃或者进入死信队列。该方法reject后，该消费者还是会消费到该条被reject的消息。
        // channel.basicReject(deliveryTag, true);
        // 消息的标识，false只确认当前一个消息收到，true确认所有consumer获得的消息（成功消费，消息从队列中删除 ）
        //channel.basicAck(1L,false);

    }

}
